#define	_CRT_SECURE_NO_WARNINGS 1

#include "Heap.h"

void TestHeap()
{
	HP hp;
	HeapInit(&hp);
	HeapPush(&hp, 1);
	HeapPush(&hp, 4);
	HeapPush(&hp, 0);
	HeapPush(&hp, 7);
	HeapPush(&hp, 3);
	HeapPush(&hp, 9);
	HeapPrint(&hp);

	HeapPop(&hp);
	HeapPrint(&hp);

	HeapDestory(&hp);
}

void HeapSort(int* a, int size)
{
	HP hp;
	HeapInit(&hp);

	for (int i = 0; i < size; ++i)
	{
		HeapPush(&hp, a[i]);
	}

	size_t j = 0;
	while (!HeapEmpty(&hp))
	{
		a[j] = HeapTop(&hp);
		++j;
		HeapPop(&hp);
	}

	HeapDestory(&hp);
}

int main()
{
	//TestHeap();

	int a[] = { 4, 2, 7, 8, 5, 1, 0, 6 };
	HeapSort(a, sizeof(a) / sizeof(int));

	for (int i = 0; i < sizeof(a) / sizeof(int); ++i)
	{
		printf("%d ", a[i]);
	}
	printf("\n");

	return 0;
}